#include <iostream>
#include <iomanip>
#include <functional>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;
//fill the set or multiset
template <typename S>
void fill(S& s)
{
  s.insert(4);
  s.insert(3);
  s.insert(5);
  s.insert(1);
  s.insert(6);
  s.insert(2);
  s.insert(5);
  s.insert(7);
}
template <typename S>
void print(S& s)
{
  copy(s.begin(),s.end(),ostream_iterator<typename S::value_type>(cout,"   "));
  cout<<endl;
}

int main()
{
  typedef set<int,greater<int> > IntSet;
  IntSet set;
  fill(set);
  print(set);
  cout<<setfill('-')<<setw(30)<<""<<setfill(' ')<<endl;

  int i = 0;
  while(true) {
    cin>>i;
    pair<IntSet::iterator, bool> p = set.insert(i);
    if(p.second) {//inserted successfully
      cout<<"inserted as "<<distance(set.begin(),p.first)<<"th"<<endl;
    }
    else{//already exsits
      cout<<"element already exists as "<<distance(set.begin(),p.first)<<"th"
	  <<endl;
    }
    print(set);
    cout<<setfill('-')<<setw(30)<<""<<setfill(' ')<<endl;
  }
}
